package io.zcoder.innoway.activities;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.zcoder.innoway.R;
import io.zcoder.innoway.adapters.ViewPagerEntryAdapter;
import io.zcoder.innoway.commons.Constants;
import io.zcoder.innoway.models.Dashboard;
import me.relex.circleindicator.CircleIndicator;

public class EntryDetailActivity extends BaseActivity implements ViewPager.OnPageChangeListener {

    @BindView(R.id.viewPager)
    ViewPager mViewPager;
    @BindView(R.id.common_close)
    ImageView mClose;
    @BindView(R.id.indicator)
    CircleIndicator mIndicator;
    public int[] mTitle = {R.string.body_mass_index, R.string.body_fat, R.string.muscle, R.string.water_s,  R.string.bone_mass, R.string.basal_metabolic, R.string.visceral_fat};

    @OnClick(R.id.common_close)
    void close() {
        finish();
    }

    private Dashboard mDashboard;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_entry_detail_activity);
        ButterKnife.bind(this);
        mClose.setVisibility(View.VISIBLE);
        mDashboard = getIntent().getParcelableExtra(Constants.DASHBOARD_EXTRAS);
        if (mDashboard == null) {
            finish();
            return;
        }

        ViewPagerEntryAdapter adapter = new ViewPagerEntryAdapter(this, getSupportFragmentManager());
        mViewPager.setAdapter(adapter);
        mViewPager.setOnPageChangeListener(this);
        mIndicator.setViewPager(mViewPager);
        int index = getIntent().getIntExtra(Constants.INDEX_EXTRAS, 0);
        mViewPager.setCurrentItem(index);
    }

    public Dashboard getDashboard() {
        return mDashboard;
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        setTitle(getString(mTitle[position]));
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
